<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<!--导入模态框-->
<div class="modal fade" data-backdrop="static" data-keyboard="false" id="modal-import-plan">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">Excel信息导入</h4>
            </div>
            <div class="modal-body">
                <form id="importForm">
                    <div class="form-group">
                        <label>模版</label>
                        <a class="out" th:href="@{/file/存档清单模板.xlsx}">点击下载</a>
                    </div>
                    <div class="form-group">
                        <label>选择Excel文件并上传</label>
                        <input id="import-file" class="btn" type="file" name="file">
                        <p class="help-block">请按模板格式进行导入，信息与模板信息对应。</p>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button id="btn-import" type="button" class="btn btn-success">
                    <span class="Bold">确定</span>
                </button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<!--上传附件-->
<div class="modal fade" data-backdrop="static" data-keyboard="false" id="modal-upload">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">上传附件</h4>
            </div>
            <div class="modal-body">
                <form id="uploadForm">
                    <div class="form-group">
                        <label>选择附件上传</label>
                        <input class="btn" type="file" name="file">
                        <p class="help-block">多个文件请自行打包上传，大小不要超过100M</p>
                        <p class="help-block text-red">多条计划附件不支持上传同名文件</p>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button shiro:hasPermission="production:make:edit" id="btn-upload" type="button"
                        class="btn btn-success">
                    <span class="Bold">上传</span>
                </button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<section class="content">
    <div class="row" style="margin-bottom: 24px">
        <a id="btn-save" shiro:hasPermission="file:found:save" href="javascript:void(0);"
           class="btn btn-info pull-right" style="margin-right: 10px">
            <span class="Bold">确定</span>
        </a>
        <!--<a shiro:hasPermission="file:found:save" href="javascript:void(0);"
           class="btn btn-success pull-right" style="margin-right: 10px"
           onclick="js.modal.open('modal-import-plan')">
            <span class="Bold">导入</span>
        </a>-->
    </div>
    <div class="row">
        <form id="sheetForm" class="form-horizontal">
            <div class="col-xs-11 col-xs-offset-1">
                <input type="hidden" name="reportType" value="1">
                <table class="t1 t3">
                    <thead>
                    <tr>
                        <td colspan="12">
                            <img th:src="@{/img/logo3.jpg}" width="64px" height="40px" style="margin-top: -30px">
                            <div style="display: inline-block;margin-top: 5px;margin-left: 20px">
                                <span style="letter-spacing: 24px;display: block;line-height: 20px">&nbsp;辽宁忠旺机械设备制造有限公司</span>
                                <span style="display: block;font-size: 12px;line-height: 20px">Liaoning Zhongwang Machinery Equipment Manufacturing Co., Ltd</span>
                            </div>
                        </td>
                        <td style="width: 8%"></td>
                    </tr>
                    <tr>
                        <td colspan="12" style="font-size: 16px;letter-spacing: 4px;">
                            存档清单
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td colspan="2" style="width: 8%">项目编号</td>
                        <td style="width: 11%;font-size: 14px;">
                            <select id="sheetForm-proCode" class="form-control" name="proCode"></select>
                        </td>
                        <td style="width: 8%">项目名称</td>
                        <td colspan="2" style="width: 21%">
                            <input id="sheetForm-proName" type="text" class="form-control" name="proName" readonly style="background-color: white">
                        </td>
                        <td style="width: 8%">项目数量</td>
                        <td style="width: 6%">
                            <input id="sheetForm-proNum" type="number" class="form-control" name="proNum" readonly style="background-color: white">
                            <input type="hidden" id="sheetForm-proId" name="proId">
                            <input type="hidden" id="sheetForm-drawType" name="drawType">
                        </td>
                        <td style="width: 6%">类型</td>
                        <td style="width: 9%">
                            <select id="sheetForm-malType" class="form-control" name="specialId">
                                <option value="">请选择</option>
                                <option th:each="special : ${specials}" th:value="${special.id}"
                                        th:text="${special.name}"></option>
                                <input type="hidden" id="specialse" name="special">
                            </select>
                        </td>
                        <td style="width: 6%">部分</td>
                        <td style="width: 12%">
                            <select id="part" class="form-control" name="partId">
                                <option value="">请选择</option>
                                <input type="hidden" id="partName" name="part">
                            </select>
                        </td>
                        <td>
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 4%">序号</td>
                        <td colspan="4">名称</td>
                        <td style="width: 14%">纸质版数量（页）</td>
                        <td colspan="2">电子版数量（件）</td>
                        <td colspan="4">备注</td>
                        <td></td>
                    </tr>
                    </thead>
                    <tbody id="out">
                    <tr>
                        <td>1</td>
                        <td colspan="4">
                            项目任务单
                            <input type="hidden" value="项目任务单" name="fileName">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>
                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>2</td>
                        <td colspan="4">
                            技术协议
                            <input type="hidden" value="技术协议" name="fileName">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>
                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>3</td>
                        <td colspan="4">
                            项目设计-控制意图协议书
                            <input type="hidden" value="项目设计-控制意图协议书" name="fileName">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>
                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>4</td>
                        <td colspan="4">
                            流体控制意图表
                            <input type="hidden" value="流体控制意图表" name="fileName">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>
                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>5</td>
                        <td colspan="4">
                            项目外观设计协议书
                            <input type="hidden" value="项目外观设计协议书" name="fileName">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>
                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>6</td>
                        <td colspan="4">
                            项目联络单
                            <input type="hidden" value="项目联络单" name="fileName">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>
                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>7</td>
                        <td colspan="4">
                            三维模型
                            <input type="hidden" value="三维模型" name="fileName">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>
                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>8</td>
                        <td colspan="4">
                            基础图
                            <input type="hidden" value="基础图" name="fileName">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>
                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>9</td>
                        <td colspan="4">
                            总布置图
                            <input type="hidden" value="总布置图" name="fileName">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>
                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>10</td>
                        <td colspan="4">
                            流体管线布置图
                            <input type="hidden" value="流体管线布置图" name="fileName">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>
                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>11</td>
                        <td colspan="4">
                            线缆桥架布置图
                            <input type="hidden" value="线缆桥架布置图" name="fileName">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>
                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>12</td>
                        <td colspan="4">
                            自动化布线及元件连接说明
                            <input type="hidden" value="自动化布线及元件连接说明" name="fileName">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>
                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>13</td>
                        <td colspan="4">
                            自动化程序
                            <input type="hidden" value="自动化程序" name="fileName">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>
                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>14</td>
                        <td colspan="4">
                            使用维护手册
                            <input type="hidden" value="使用维护手册" name="fileName">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>
                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>15</td>
                        <td colspan="4">
                            设计图纸
                            <input type="hidden" value="设计图纸" name="fileName">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>
                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>16</td>
                        <td colspan="4">
                            图纸变更单
                            <input type="hidden" value="图纸变更单" name="fileName">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>
                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>17</td>
                        <td colspan="4">
                            制作件清单
                            <input type="hidden" value="制作件清单" name="fileName">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>
                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>18</td>
                        <td colspan="4">
                            制作件清单变更单
                            <input type="hidden" value="制作件清单变更单" name="fileName">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>
                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>19</td>
                        <td colspan="4">
                            外购件计划单及附件
                            <input type="hidden" value="外购件计划单及附件" name="fileName">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>
                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>20</td>
                        <td colspan="4">
                            外购件计划变更单及附件
                            <input type="hidden" value="外购件计划变更单及附件" name="fileName">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>
                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>21</td>
                        <td colspan="4">
                            涂装设计清单
                            <input type="hidden" value="涂装设计清单" name="fileName">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>
                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>22</td>
                        <td colspan="4">
                            概要设计文档
                            <input type="hidden" value="概要设计文档" name="fileName">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>
                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>23</td>
                        <td colspan="4">
                            详细设计文档
                            <input type="hidden" value="详细设计文档" name="fileName">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>
                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>24</td>
                        <td colspan="4">
                            软件程序
                            <input type="hidden" value="软件程序" name="fileName">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>
                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>25</td>
                        <td colspan="4">
                            数据库备份
                            <input type="hidden" value="数据库备份" name="fileName">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>
                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td>
                            <span class="out-add" title="添加"><i class="fa fa-plus text-info"></i> </span>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <div class="col-xs-10 col-xs-offset-1" style="font-size: 14px;line-height: 200%;">
                <div class="col-xs-3" style="padding-left: 0">提报人： [[${session.user.name}]]</div>
                <div class="col-xs-3 bottom form-inline">联系电话：
                    <input class="form-control" style="width:60%;border: none;border-bottom: 1px solid #000;" type="text" name="postTel" >
                </div>
            </div>
        </form>
    </div>
<!--
    <div th:include="include :: tip"></div>
-->
</section>
<div th:include="include :: footer"></div>

<script th:src="@{/plugin/SheetJs/xlsx.core.min.js}"></script>
<script th:inline="javascript">
    let tempUrl;

    /** 计算表格序号 */
    function computerNo() {
        $("table tbody tr").each(function (i, e) {
            $(this).children("td:first").text(i + 1);
        });
    }
    /** 部分获取*/
    function getPartName(){
        let code = $("#sheetForm-proCode").val();
        let type = $("#sheetForm-malType").val();
        /** 部分的级联获取*/
        js.get({
            url: ctx + 'drawChange/add/part/list',
            data: {
                code :code,
                type: type
            },
            success: function (result) {
                $("#part").empty().append(`<option value="">请选择</option>`);
                result.forEach(value => {
                    if (value) {
                        $("#part").append(`<option value="${value.id}">${value.proPart}</option>`);
                    }
                })
            }
        })
    }



    $(function () {

        /** 项目编号下拉框 */
        js.select2({
            id: 'sheetForm-proCode',
            placeholder:'',
            ajax: {
                url: function(){
                    return ctx + 'production/add/designProject/list'
                },
                processResults: function (data, page) {
                    let array = data;
                    for (let i = 0; i < data.length; i++) {
                        array[i]["proId"] = array[i]['id'];
                        array[i]["id"] = array[i]['code'];
                        array[i]["text"] = array[i]['code'];

                    }
                    return { results: array };
                },
            }
        });
        /** 项目编号下拉框选中 */
        $("#sheetForm-proCode").on("select2:select",function(){
            ;
            $("#sheetForm-proName").val($(this).select2("data")[0].name);
            $("#sheetForm-proNum").val($(this).select2("data")[0].num);
            $("#sheetForm-proId").val($(this).select2("data")[0].proId);
            $("#sheetForm-drawType").val($(this).select2("data")[0].drawType);

        });

        $("#sheetForm-malType").change(function (){
            /** 部分的级联获取*/
            getPartName();

        })


        /** 添加一行 */
        $("#sheetForm").on('click', '.out-add', function () {
            $(this).parents("tr").after(`
                    <tr>
                       <td name="orderNum"></td>
                       <td colspan="4">
                            <input style="text-align:left;" type="text" class="form-control" name="fileName" autocomplete="off">
                        </td>
                        <td>
                            <input type="number" min="0" class="form-control" name="pageNum" autocomplete="off">
                        </td>
                        <td colspan="2">
                            <input type="number" min="0" class="form-control" name="picecNum" autocomplete="off">
                        </td>

                        <td colspan="4">
                            <input type="text" class="form-control" name="remark" autocomplete="off">
                        </td>
                        <td>
                            <span class="out-add" title="添加"><i class="fa fa-plus text-info"></i> </span>
                            <span class="out-del" title="删除"><i class="fa fa-remove text-red"></i> </span>
                        </td>
                    </tr>
            `);
            computerNo();
        });

        /** 导入 */
        $('#btn-import').click(function() {

            let files = $("#import-file")[0].files;
            // let files = e.target.files;
            let fileReader = new FileReader();
            fileReader.onload = function(ev) {
                try {
                    let data = ev.target.result,
                        workbook = XLSX.read(data, {type: 'binary'}), // 以二进制流方式读取得到整份excel表格对象
                        plans = []; // 存储获取到的数据
                    // 遍历每张表读取
                    for (let sheet in workbook.Sheets) {
                        if (workbook.Sheets.hasOwnProperty(sheet)) {
                            plans = plans.concat(XLSX.utils.sheet_to_json(workbook.Sheets[sheet]));
                            break; // 只取第一张表
                        }
                    }
                    if (plans.length === 0) {
                        js.modal.alert("无法读取文件内容");
                    } else {
                        $("#out").empty();
                        plans.forEach((value, index) => {
                            let r = value['备注'] || '';
                            $("#out").append(`
                                <tr>
                                    <td></td>
                                    <td colspan="3">
                                        <input style="text-align:left;" type="text" class="form-control" name="fileName" value="${value['名称']}" autocomplete="off">
                                    </td>
                                    <td colspan="3">
                                        <input type="number" min="0" class="form-control" name="picecNum" value="${value['件数']}"  autocomplete="off">
                                    </td>
                                    <td>
                                        <input type="number" min="0" class="form-control" name="pageNum" value="${value['页数']}" autocomplete="off">
                                    </td>
                                    <td colspan="2">
                                       ${makeTypeHtml}
                                    </td>
                                    <td colspan="2">
                                        <input type="text" class="form-control" name="remark" value="${r}"  autocomplete="off">
                                    </td>
                                    <td>
                                        <span class="out-add" title="添加"><i class="fa fa-plus text-info"></i> </span>
                                        <span class="out-del" title="删除"><i class="fa fa-remove text-red"></i> </span>
<!--                                        <span class="out-upload" title="上传附件"><i class="fa fa-upload text-success"></i> </span>-->
                                    </td>
                                </tr>

                            `);
                            $("#out").find("select[name=fileType]:last").val(value['类型'])
                        });
                        computerNo();
                        js.modal.hide("modal-import-plan");
                    }
                } catch (e) {
                    js.modal.alert("无法读取文件或文件类型有错误");
                }
            };
            // 以二进制方式打开文件
            fileReader.readAsBinaryString(files[0]);
        });

        /** 删除行 */
        $('#sheetForm').on('click', '.out-del', function () {
            $(this).parents("tr").remove();
            computerNo();
        });

        $("#sheetForm").on('click', '.out-upload', function () {
            tempUrl = $(this).parents("tr").find("input[name=url]");
            js.modal.open('modal-upload');
        });
        /** 初始化验证 */
        js.validate.init("uploadForm", {
            fields: {
                file: {
                    validators: {
                        notEmpty: {message: '上传文件不能为空'}
                    }
                }
            }
        });
        /** 上传附件 */
        $("#btn-upload").click(function () {
            var $this = $(this);
            $this.attr('disabled', true);
            js.validSubmit({
                formId: "uploadForm",
                url: ctx + "production/add/upload",
                data: new FormData($("#uploadForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.alert(result.msg);
                        tempUrl.val(result.data);
                        js.modal.hide("modal-upload");
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
            $this.attr('disabled', false);
        });
        /** 重置表单及验证 */
        js.modal.hideEvent("modal-upload", function () {
            js.validate.reset("uploadForm");
            js.reset("uploadForm");
        })

        /** 保存计划单 */
        $("#btn-save").click(function () {
            let $this = $(this);
            $("#specialse").val($("#sheetForm-malType option:selected").text());
            $("#partName").val($("#part option:selected").text());
            let res = js.vd({
                id: 'sheetForm',
                notEmpty: ['proCode','part','partId', 'postTel','specialId','fileName']
            })
            if (!res) {
                return;
            }
            $this.attr('disabled', true);
            js.submit({
                formId: "sheetForm",
                url: ctx + 'create/file/first/save',
                data: new FormData($("#sheetForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        if(result.data===-2){
                            alert(result.msg);
                            return;
                        }
                        location.href = ctx + "create/file/list";
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
            $this.removeAttr('disabled');
        });

    });
</script>
</body>
</html>
